package com.spicy_clock;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class CollectionActivity extends Activity {

    private GridView gView;
    private int[] grid_item_image = new int[]{
	    R.drawable.a, R.drawable.b, R.drawable.c, R.drawable.d,
	    R.drawable.e, R.drawable.f, R.drawable.g, R.drawable.h,
	    R.drawable.i, R.drawable.j, R.drawable.k, R.drawable.l,
	    R.drawable.m, R.drawable.n, R.drawable.o, R.drawable.p}; 	

    private int[] grid_item_video = new int []{
	    R.raw.video_1,R.raw.video_2,R.raw.video_3,R.raw.video_4,
	    R.raw.video_5,R.raw.video_6,R.raw.video_7,R.raw.video_8,
	    R.raw.video_9,R.raw.video_10,R.raw.video_11,R.raw.video_12,
	    R.raw.video_13,R.raw.video_14,R.raw.video_15,R.raw.video_16};
    
    private String[] grid_item_activate_time = new String[] {
    "20120101","20120101","20120101","20120101",
    "20120101","20120101","20120101","20120101",
    "20120101","20120101","20120101","20120101",
    "20120101","20120101","20120101","20120101"};
    private int[] grid_item_is_active = {
	    0,0,0,0,
	    0,0,0,0,
	    0,0,0,0,
	    0,0,0,0,};
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_collection);
        
        gView = (GridView)findViewById(R.id.gv);
        GridViewAdapter adapter = new GridViewAdapter(grid_item_image, grid_item_video, grid_item_activate_time, grid_item_is_active, this);

        gView.setAdapter(adapter);
        
        
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_collection, menu);
        return true;
    }

    
}

class GridViewAdapter extends BaseAdapter
{
    private LayoutInflater inflater;
    private List<GridViewItem> gridList;
    private ImageView gridView;
    
    public GridViewAdapter(int[] imageId,int[] videoId,String[] activateTime,int[] isActive,Context ct )
	{
	    super();
	    gridList = new ArrayList<GridViewItem>();
	    inflater = LayoutInflater.from(ct);
	    for(int i = 0; i<imageId.length; i++)
	    {
		GridViewItem item = new GridViewItem(imageId[i],videoId[i],activateTime[i],isActive[i]);
		gridList.add(item);
	    }
	}
    public int getCount()
	{
	    if(gridList != null)
	    {
		return gridList.size();
	    }
	    return 0;
	}
    public Object getItem(int arg0)
	{
	    return gridList.get(arg0);
	}
    public long getItemId(int arg0)
	{
	    return arg0;
	}
    public View getView(int arg0, View arg1, ViewGroup arg2)
	{
	    if(arg1 == null)
	    {
		arg1 = inflater.inflate(R.layout.collection_item, null);
		gridView = (ImageView)arg1.findViewById(R.id.itemImage);
		if(gridList.get(arg0).isActive())
		{
		    gridView.setImageResource(gridList.get(arg0).getImageId());    
		}
		else
		{
		    gridView.setImageResource(gridList.get(arg0).getImageId()); 
		    gridView.setBackgroundDrawable(arg1.getResources().getDrawable(R.drawable.mask));
		    gridView.getBackground().setAlpha(255);
		}
		
	    }
		return arg1;
	}
    
    
}
class GridViewItem
{
    private int gridItemImageId;
    private int gridItemVideoId;
    private String gridItemActivateTime;
    private int isActive;
    
    public GridViewItem()
	{
	    super();
	}
    public GridViewItem(int imageId,int videoId,String activateTime,int isActive)
	{
	    this.gridItemImageId = imageId;
	    this.gridItemVideoId = videoId;
	    this.gridItemActivateTime = activateTime;
	    this.isActive = isActive;
	    
	}
    public int getImageId()
	{
	    return this.gridItemImageId;
	}
    public int getvideoid()
	{
	    return this.gridItemVideoId;
	}
    public String getActivateTime()
	{
	    return this.gridItemActivateTime;
	}
    public Boolean isActive()
	{
	    return (1==this.isActive)?true:false;
	}
}
